import { HttpClient } from '@angular/common/http';
import { Component } from '@angular/core';

@Component({
  selector: 'app-tab1',
  templateUrl: 'tab1.page.html',
  styleUrls: ['tab1.page.scss'],
})
export class Tab1Page {
  constructor(public http: HttpClient) {}

  res: Result;
  icons = ['icon1.png', 'icon2.png', 'icon3.png', 'icon4.png'];
  // 把返回值动态组成一个新的数据项
  data() {
    return [
      {
        title: '首页推荐/1F',
        icon: 'apps',
        data: this.res.recommendedItems,
      },
      {
        title: '最新上架/2F',
        icon: 'bag-add',
        data: this.res.newArrivalItems,
      },
      {
        title: '热销单品/3F',
        icon: 'bonfire',
        data: this.res.topSaleItems,
      },
    ];
  }
  ngOnInit(): void {
    const url = 'http://101.96.128.94:9999/data/product/index.php';
    this.http.get(url).subscribe((res: any) => {
      console.log(res);
      this.res = res;
    });
  }
}

interface Result {
  carouselItems: CarouselItem[];
  newArrivalItems: ResultItem[];
  recommendedItems: ResultItem[];
  topSaleItems: ResultItem[];
}
interface CarouselItem {
  cid: string;
  href: string;
  img: string;
  title: string;
}
interface ResultItem {
  details: string;
  href: string;
  pic: string;
  pid: string;
  price: number;
  title: string;
}
